<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="./css/account.css">
	<script src="js\jqery-3.5.1.min.js"></script>

</head>
<body>
    <div class="plantform ">
        <img id="tx" src="https://ss1.bdstatic.com/70cFuXSh_Q1YnxGkpoWK1HF6hhy/it/u=1500169642,1950901279&fm=26&gp=0.jpg" alt="">
        <div id="account">

            <div class="var">
                
                账户
            </div>
            <div class="val">
                233333333

            </div>
            <form  enctype="multipart/form-data" method="post">
                <input id="file" type="file" name="file" >
                <button  id="submit2">上传</button>
            </form>
            <script>
               
            </script>
            
        </div>
        <div id="gender">
            
            <select name="gender" id="selectgender" autocomplete="off">
                <option value="female" id='female' >♀</option>
                <option value="male" id='male' >♂</option>
            </select>
        </div>

        <div id="name">
            <div class="var">
                昵称
            </div>
            <input type="text" placeholder="DOGE">
        </div>
        <div id="password">
            <div class="var">
                密码
            </div>
            <input id=password1 type="text" placeholder="修改密码"><br>
            <input id=password2 type="text" placeholder="确认密码">
        </div>
        <div id="phone">
            <div class="var">
                电话
            </div>
            <input type="text" placeholder="10086">
        </div>
        <div id="shopcar">
            <svg t="1605864400644" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="2801" width="200" height="200"><path d="M273.9 842a60 60 0 1 0 120 0 60 60 0 1 0-120 0zM733.9 842a60 60 0 1 0 120 0 60 60 0 1 0-120 0zM807.4 732H321.2c-17.8 0-34.8-6.7-47.8-18.8s-20.8-28.6-22.1-46.4L215.9 152h-72c-16.6 0-30-13.4-30-30s13.4-30 30-30h100c15.8 0 28.8 12.2 29.9 27.9l7.7 112.1H840c19.6 0 38.5 8.3 51.7 22.8 13.2 14.5 19.8 34 18 53.5l-32.7 360c-1.6 17.4-9.6 33.5-22.5 45.4-12.9 11.8-29.6 18.3-47.1 18.3zM285.7 292l25.6 370.7c0.1 1.8 0.8 4.4 3.2 6.6 2.4 2.2 5 2.7 6.8 2.7h486.1c1.8 0 4.4-0.5 6.7-2.6 2.4-2.2 3.1-4.7 3.2-6.5l32.7-360c0.1-1.6 0-4.8-2.6-7.6s-5.7-3.3-7.4-3.3H285.7z" p-id="2802" fill="#ffffff"></path></svg>
        </div>
        <span id="submit" onclick=changeinfo()>提交修改</span>
        
    </div>
    <p id="bottom"></p>

    <!-- <script>
        setTimeout(function(){
            window.location.reload();
        },1000);
    </script> -->
    <script>
        function showmyinfo(){
            var token = document.cookie.split(";")[0]; 
            $.ajax({
                url:"http://localhost/user/showmyinfo",
                ret: "0",
                type:"POST",
                dataType: "json",
                data: JSON.stringify({
                    token: token,
                }),
                success: function(data){
                    if (data.ret!="0"){
                        window.location.href="http://localhost/login.html"
                    }  
                    else{
                        console.log(data)
                        var thispath = data.image;
                        var imagepath = thispath.split('/')[1] +"/" + thispath.split('/')[2];
                        $(".val").text(data.account)
                        $("#name input").attr("placeholder",data.name)
                        $("#phone input").attr("placeholder",data.phone)
                        $("img").attr("src", imagepath)
                        if (data.sex=="male"){
                            $("#male").attr("selected","selected")
                        }
                        else{
                            $("#female").attr("selected","selected")
                        }
                    }
                }
            })
        }

       

        function changeinfo(){
            var token = document.cookie.split(";")[0]; 
            $.ajax({
                url:"http://localhost/user/changeinfo",
                ret: "0",
                type:"POST",
                dataType: "json",
                data: JSON.stringify({
                    token: token,
                    newname: $("#name input").val(),
                    newpassword1: $("#password1").val(),
                    newpassword2: $("#password2").val(),
                    newphone: $("#phone input").val(),
                    newsex: $("#selectgender").val(),
                }),
                success: function(data){
                    if (data.ret!="0"){
                        window.location.href="http://localhost/login.html"
                    }  
                    else{
                        console.log(data)
                        alert(data.msg)
                    }       
                }
            })
        }
       
        $(document).ready(function(){
            showmyinfo();

            $("#bottom").append("<script src=\".\/js\/uploadimage.js\"><\/script>")
            
        })
    </script>
</body>
</html>